//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    class SheetFormatProperties : IOfficeXmlSerializable
    {
        internal const int DefaultDefaultColumnWidth = 8;
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("sheetFormatPr"))
            {
                BaseColumnWidth = c.GetOptionalInteger("baseColWidth", DefaultDefaultColumnWidth);
                DefaultColumnWidth = c.GetOptionalDouble("defaultColWidth", DefaultDefaultColumnWidth);//\\change this
                DefaultRowHeight = PointsToPixelConverter.ToPixel( c.GetDouble("defaultRowHeight"));
                CustomHeight = c.GetOptionalBoolean("customHeight", false);
                ZeroHeight = c.GetOptionalBoolean("zeroHeight", false);
                ThickTop = c.GetOptionalBoolean("thickTop", false);
                ThickBottom = c.GetOptionalBoolean("thickBottom", false);
                _outlineLevelRow = c.GetOptionalInteger("outlineLevelRow", 0);
                OutlineLevelCol = c.GetOptionalInteger("outlineLevelCol", 0);
            }
        }
        internal const double GlobalDefaultRowHeight = 20; // 20 pixels

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("sheetFormatPr"))
            {
                c.SetOptionalInteger("baseColWidth", BaseColumnWidth, DefaultDefaultColumnWidth);
                c.SetOptionalDouble("defaultColWidth", DefaultColumnWidth, DefaultDefaultColumnWidth);//\\change this
                c.SetDouble("defaultRowHeight", PointsToPixelConverter.ToPoint(DefaultRowHeight));
                c.SetOptionalBoolean("customHeight", CustomHeight , false);
                c.SetOptionalBoolean("zeroHeight", ZeroHeight , false);
                c.SetOptionalBoolean("thickTop", ThickTop , false);
                c.SetOptionalBoolean("thickBottom", ThickBottom , false);
                c.SetOptionalInteger("outlineLevelRow", _outlineLevelRow , 0);
                c.SetOptionalInteger("outlineLevelCol", OutlineLevelCol , 0);
            }
        }

        #endregion

        public int BaseColumnWidth { get; set; }

        public double DefaultColumnWidth { get; set; }

        public double DefaultRowHeight { get; set; }

        public bool CustomHeight { get; set; }

        public bool ZeroHeight { get; set; }

        public bool ThickTop { get; set; }

        public bool ThickBottom { get; set; }

        private int _outlineLevelRow;

        public int OutlineLevelRow
        {
            get { return _outlineLevelRow; }
            set { _outlineLevelRow = value; }
        }

        public int OutlineLevelCol { get; set; }

        public SheetFormatProperties()
        {
            BaseColumnWidth = 8;
            DefaultColumnWidth = DefaultDefaultColumnWidth;
            DefaultRowHeight = GlobalDefaultRowHeight;
        }
    }
}
